﻿using System.Xml;

namespace OpenDeploy.Infrastructure.Helper;

/// <summary>
/// 项目帮助类
/// </summary>
public class ProjectHelper
{
    /// <summary>
    /// 解析项目引用
    /// </summary>
    /// <param name="projectFileName">项目文件路径(*.csproj)</param>
    public static List<string> ParseProjectReference(string projectFileName)
    {
        List<string> references = [];
        try
        {
            XmlDocument doc = new();
            doc.Load(projectFileName);
            XmlNodeList projectReferenceNodes = doc.GetElementsByTagName("ProjectReference");
            for (int i = 0; i < projectReferenceNodes.Count; i++)
            {
                XmlNode projectReferenceNode = projectReferenceNodes[i]!;
                for (int j = 0; j < projectReferenceNode.ChildNodes.Count; j++)
                {
                    XmlNode childNode = projectReferenceNode.ChildNodes[j]!;
                    if (childNode.Name == "Name")
                    {
                        references.Add(childNode.InnerText);
                    }
                }
            }
        }
        catch (Exception)
        {
            
        }
        return references;
    }
}
